﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Secretaria_HabilitarReunion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       // cboSede.seleciona += new cboSelected(cboSede_seleciona);
        //CboTipoPlanilla.seleciona += new cboSelected(CboTipoPlanilla_seleciona);
        showview();
        if (!IsPostBack)
        {
            
            /*
            if (biFactory.User().IdSede > 0)
            {
                cboSede.BindCBO();
                cboSede.Value = biFactory.User().IdSede.ToString();
                if (biFactory.User().IdPerfil > 0)
                    cboSede.Enabled = false;
                //cargo el las planillas segun el idsede
                cboSede_seleciona("1", "1");
            }
             */
        }
    }

    void CboTipoPlanilla_seleciona(string param1, string param2)
    {
        showview();
    }

    void cboSede_seleciona(string param1, string param2)
    {
        CboTipoPlanilla.SourceData = "proc_getTipoPlanillaSede " + cboSede.Value;
        CboTipoPlanilla.NameId = "idTipoPlanilla";
        CboTipoPlanilla.NameDescript = "Detalle";
        CboTipoPlanilla.TipoOrigen = Controles_cboGeneric.TipoSource.Procedure;
        CboTipoPlanilla.BindCBO();
    }

    private void showview()
    {
        DataTable dt = SchoolsBI.Materia.Tabla("SELECT * FROM ConceptoReuniones");
        GridView1.DataSource = dt;
        GridView1.DataBind();
        cmdGuardar.Visible = (dt.Rows.Count > 0);
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int estado = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "Habilitada"));
            if (estado == 1)
            {
                e.Row.BackColor = System.Drawing.Color.FromArgb(252, 211, 155);
                ((CheckBox)e.Row.FindControl("ckhHabiliado")).Checked = true;
            }
        }
    }
    protected void cmdGuardar_Click(object sender, EventArgs e)
    {
        Guardar();
    }

    private void Guardar()
    {
        //recorrrer todo los items 

        foreach (GridViewRow rg in GridView1.Rows)
        {

            CheckBox estado = (CheckBox)rg.FindControl("ckhHabiliado");
            SchoolsBI.ConceptoReuniones r = SchoolsBI.ConceptoReuniones.Buscar("id = " + GridView1.DataKeys[rg.RowIndex].Value);
            if (estado.Checked){ r.Habilitada= 1; }
            else { r.Habilitada = 0; };
            r.Actualizar();
        }
        showview();
    }
}
